-- NewPlayerClothesRender 对 Res.NewPlayerClothesNode 的解析 适用 NewPlayerPanel 幻化相关

local ClassRef = app.mvc.createRenderClass(...)

function ClassRef.create(node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.NewPlayerClothesNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init()
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self:setContentSize(self._ui["Panel"]:getContentSize())
	self._textTips = self._ui["Panel/clothes_bg/Text"]

	self._ui["Panel"]:addTouchEventListener(function(sender, eventType)
		if eventType == ccui.TouchEventType.ended then
			executeFunc(self._onClick, self)
		end
	end)

	self:refresh()
end

-- data = fashionID
function ClassRef:refresh()
	if self._data and 0 ~= self._data then

		self._ui["grade"]:setVisible(true)
		self._ui["icon"]:setVisible(true)
		self._ui["clothes_bg"]:setVisible( false )
		local conf = GD:getClothesConfig( self._data )
		local resConf = GD:getClothesResConfig( self._data )
		self._ui["icon"]:loadTexture( GD:formatIconFilePath(Enums.ItemBagType.equip, resConf.icon) )
		self._ui["grade"]:loadTexture( Res.Qulity_Icon_BgPoint[tonumber( conf.quality )] )
		self:setClickEnable( true )
		self:setUpgradeIngEffectVisible(true)	
	else
		self._ui["icon"]:setVisible(false)
		self._ui["clothes_bg"]:setVisible( true )
		self:setClickEnable( false )
		self:setUpgradeIngEffectVisible(false)
	end
end

function ClassRef:setUpgradeIngEffectVisible(b)
	self._ui['Panel/ani']:setVisible(b)
end

--添加播放幻化特效
function ClassRef:addStartEffect()
	if self._upgradeAni then
		return
	end

	self:setUpgradeIngEffectVisible(false)
	self._upgradeAni = cc.CSLoader:createNode(Res.BaseUpgradeAmi)
	local timelime = self._upgradeAni:getTimeline()
	self._ui["Panel"]:addChild(self._upgradeAni)
	self._upgradeAni:setPosition(self._ui["Panel/ani"]:getPosition())
	if timelime then
		timelime:setLastFrameCallFunc(handler(self, self._onStartEffectEnd))
		self._upgradeAni:getTimeline():gotoFrameAndPlay(0, false)
	end
end

function ClassRef:_onStartEffectEnd()
	if self._upgradeAni then
		self._upgradeAni:removeFromParent(true)
		self._upgradeAni = nil
	end
	self:setUpgradeIngEffectVisible(true)
end

-- 时装位DefPos处理
function ClassRef:setClothesDefPos(pos)
	self._clothesPos = pos
	self._ui["icon"]:loadTexture(GD:getEquipPosDefIcon(pos))
end

function ClassRef:getClothesDefPos()
	return self._clothesPos
end

function ClassRef:setClickEnable(b)
	self._ui["Panel"]:setTouchEnabled(b)
end

function ClassRef:setClickHandler(func)
	self._onClick = func
end

return ClassRef
